/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xinxi.dms.service;

import com.xinxi.dms.dao.MaintainDao;
import com.xinxi.dms.po.Maintain;
import java.util.List;

/**
 *
 * @author zhigu
 */
public class MaintainServiceIMPL implements IMaintainService{
    MaintainDao maintainDao = new MaintainDao();
    @Override
    public boolean add(Maintain maintain) {
        String sql = "insert into maintain(roomid,reason,repairtime) values(?,?,now())";
        Object[] params={maintain.getRoomid(),maintain.getReason()};
        return maintainDao.update(sql, params);
    }

    @Override
    public List<Maintain> findAll() {
        String sql="select m.id,m.reason,m.repairtime,m.maintaintime,m.maintainreason,m.maintainer,"
                + "r.buildingno,r.unitno,r.roomno "
                + "from maintain as m ,room as r "
                + "where m.roomid = r.roomid";
        Object[] params={};
        return maintainDao.query(sql, Maintain.class, params);
    }

    @Override
    public boolean update(Maintain maintain) {
        String sql="update maintain set maintainreason = ? ,"
                + "maintaintime = now(),maintainer = ? where id = ? ";
        Object[] params={maintain.getMaintainreason(),maintain.getMaintainer(),maintain.getId()};
        return maintainDao.update(sql, params);
    }
    
    
    
}
